package howl.types;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

import compiler.HowlToken;
import compiler.TokenReader;
import compiler.exceptions.HowlParserException;
import compiler.terminals.OFTEN;
import compiler.terminals.TIMEUNIT;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Frequency {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	private TIMEUNIT timeunit;
	
	@Persistent
	private OFTEN often;
	
	@Persistent
	private String when;
	
	@Persistent
	private Integer rate;


	public Frequency() {
		super();
	}
	
	public static Frequency newFrequency(compiler.terminals.Frequency f) {
		Frequency ret = new Frequency();
		ret.timeunit = f.getTimeunit();
		ret.often = f.getOften();
		ret.when = f.getWhen();
		ret.rate = f.getRate();
		return ret;
	}

	public Frequency(Long id, TIMEUNIT timeunit, OFTEN often, String when,
			Integer rate) {
		super();
		this.timeunit = timeunit;
		this.often = often;
		this.when = when;
		this.rate = rate;
	}

	/**
	 * @return the timeunit
	 */
	public TIMEUNIT getTimeunit() {
		return timeunit;
	}

	/**
	 * @param timeunit the timeunit to set
	 */
	public void setTimeunit(TIMEUNIT timeunit) {
		this.timeunit = timeunit;
	}

	/**
	 * @return the often
	 */
	public OFTEN getOften() {
		return often;
	}

	/**
	 * @param often the often to set
	 */
	public void setOften(OFTEN often) {
		this.often = often;
	}

	/**
	 * @return the when
	 */
	public String getWhen() {
		return when;
	}

	/**
	 * @param when the when to set
	 */
	public void setWhen(String when) {
		this.when = when;
	}

	/**
	 * @return the rate
	 */
	public Integer getRate() {
		return rate;
	}

	/**
	 * @param rate the rate to set
	 */
	public void setRate(Integer rate) {
		this.rate = rate;
	}

	
}
